<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id='demo' index='1'></div>
</body>
<script>
    //获取元素的属性值
    //(1)element.属性
    var div = document.querySelector('div')
    console.log(div.id);
    // element.getAttribute('属性')
    div.id = 'demos'
    console.log(div.id);
    div.setAttribute('index', 2)
</script>

</html>